<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: E73AN
  Date: 2018/5/29
  Time: 12:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户中心</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <ul class="nav justify-content-end">
        <li class="nav-item">
            <a class="nav-link disabled" href="#">
                <span class="badge badge-primary">${commons.roleName(user.role)} </span>
                ${user.name}
            </a>
        </li>
        <li class="nav-item">
            <a href="${pageContext.request.contextPath}/logout" class="nav-link" >登出</a>
        </li>
    </ul>
    <div style="margin-top: 20px">
        <c:if test="${msg != null}">
            <div class="alert alert-primary" role="alert">
                    ${msg}
            </div>
        </c:if>
        <c:if test="${error != null}">
            <div class="alert alert-danger" role="alert">
                    ${error}
            </div>
        </c:if>
    </div>

    <div class="row">
        <div class="col-md-3">
            <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                <a class="nav-link active" id="v-user-info-tab" data-toggle="pill" href="#v-user-info" role="tab" aria-controls="v-user-info" aria-selected="true">个人信息</a>
                <c:if test="${user.role.equals('ROLE_STUDENT')}">
                    <a class="nav-link" id="v-user-course-tab" data-toggle="pill" href="#v-user-course" role="tab" aria-controls="v-user-course" aria-selected="false">课程查询</a>
                </c:if>
                <c:if test="${user.role.equals('ROLE_TEACHER')}">
                    <a class="nav-link" id="v-teacher-user-tab" data-toggle="pill" href="#v-teacher-user-course" role="tab" aria-controls="v-teacher-user-course" aria-selected="false">学生课程信息</a>
                </c:if>
                <c:if test="${user.role.equals('ROLE_ADMIN')}">
                    <a class="nav-link" id="v-admin-user-role-tab" data-toggle="pill" href="#v-admin-user-role" role="tab" aria-controls="v-admin-user-role" aria-selected="false">角色管理</a>
                </c:if>
            </div>
        </div>
        <div class="col-md-9">
            <div class="tab-content" id="v-pills-tabContent">
                <div class="tab-pane fade show active" style="width: 75%" id="v-user-info" role="tabpanel" aria-labelledby="v-user-info-tab">
                    <h4>个人信息</h4>
                    <form action="${pageContext.request.contextPath}/home/updateUser/${user.id}" ModelAttribute="user" method="post" name="user" class="form-group" style="margin-top: 30px">
                        学号：<input type="text" value="${user.identifyNum}" disabled placeholder="学号" class="form-control"><br>
                        姓名：<input type="text" name="name" placeholder="姓名" value="${user.name}" class="form-control"><br>
                        性别：<select title="性别" name="sex" class="custom-select">
                        <c:choose>
                            <c:when test="${user.sex.equals('男')}">
                                <option value="男" selected>男</option>
                                <option value="女">女</option>
                            </c:when>
                            <c:otherwise>
                                <option value="男">男</option>
                                <option value="女" selected>女</option>
                            </c:otherwise>
                        </c:choose>
                    </select><br><br>
                        年龄：<input type="number" name="age" placeholder="年龄" value="${user.age}" class="form-control"><br>
                        密码：<input type="password" name="password" placeholder="密码" value="${user.password}" class="form-control"><br>
                        <input type="submit" value="修改" class="btn btn-primary">
                    </form>
                </div>
                <div class="tab-pane fade" id="v-user-course" role="tabpanel" aria-labelledby="v-user-course-tab" style="width: 75%">
                    <c:if test="${user.role.equals('ROLE_STUDENT')}">
                        <h4>课程成绩</h4>
                        <table class="table table-hover" style="margin-top: 30px">
                            <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">课程代号</th>
                                <th scope="col">课程名称</th>
                                <th scope="col">课程分数</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:choose>
                                <c:when test="${scores != null}">
                                    <c:forEach items="${scores}" var="score" varStatus="status">
                                        <tr>
                                            <td scope="row">${status.index+1}</td>
                                            <td>${score.course.courseCode}</td>
                                            <td>${score.course.name}</td>
                                            <td>${score.score}</td>
                                        </tr>
                                    </c:forEach>
                                </c:when>
                            </c:choose>
                            </tbody>
                        </table>
                        <c:if test="${scores == null}">
                            <div class="alert alert-primary" role="alert">
                                该学生暂无选课信息
                            </div>
                        </c:if>
                    </c:if>
                </div>
                <div class="tab-pane fade" id="v-teacher-user-course" role="tabpanel" aria-labelledby="v-teacher-user-course-tab">
                    <c:if test="${user.role.equals('ROLE_TEACHER')}">
                        <h4>查看学生选课信息</h4>
                        <table class="table table-hover" style="margin-top: 30px">
                            <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">学生号</th>
                                <th scope="col">学生姓名</th>
                                <th scope="col">操作</th>
                            </tr>
                            </thead>

                            <c:choose>
                                <c:when test="${students != null}">
                                    <c:forEach items="${students}" var="student" varStatus="status">
                                        <tr>
                                            <td scope="row">${status.index+1}</td>
                                            <td>${student.identifyNum}</td>
                                            <td>${student.name}</td>
                                            <td><a href="${pageContext.request.contextPath}/home/student/${student.id}" target="_blank">查看</a></td>
                                        </tr>
                                    </c:forEach>
                                </c:when>
                            </c:choose>
                        </table>
                    </c:if>
                </div>
                <div class="tab-pane fade" id="v-admin-user-role" role="tabpanel" aria-labelledby="v-admin-user-role-tab">
                    <c:if test="${user.role.equals('ROLE_ADMIN')}">
                        <h2>角色管理</h2>
                        <h4>教师列表</h4>
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">教师号</th>
                                <th scope="col">教师名称</th>
                                <th scope="col">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${teachersList != null}">
                                <c:forEach items="${teachersList}" var="teacher" varStatus="status">
                                    <tr>
                                        <td scope="row">${status.index+1}</td>
                                        <td>${teacher.identifyNum}</td>
                                        <td>${teacher.name}</td>
                                        <td><a href="${pageContext.request.contextPath}/home/deleteUser/${teacher.id}">删除</a></td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                        </table>
                        <br>
                        <h4>学生列表</h4>
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">学生号</th>
                                <th scope="col">学生名称</th>
                                <th scope="col">操作</th>
                            </tr>
                            </thead>

                            <tbody>
                            <c:if test="${studentsList != null}">
                                <c:forEach items="${studentsList}" var="student" varStatus="status">
                                    <tr>
                                        <td scope="row">${status.index+1}</td>
                                        <td>${student.identifyNum}</td>
                                        <td>${student.name}</td>
                                        <td><a href="${pageContext.request.contextPath}/home/deleteUser/${student.id}">删除</a></td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                        </table>
                    </c:if>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>